package spe.ui.action;

import java.util.List;

import org.eclipse.gef.Request;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.ui.IWorkbenchPart;

import spe.ui.editor.command.ElementDeleteCommand;
import spe.ui.editor.part.AbstractElementNodeEditPart;

public class CancelableDeleteAction extends DeleteAction 
{
	public static final String ID = CancelableDeleteAction.class.getName();
	public static final String REQ_TYPE = "CANCELABLEDELTE";
	
	private Request request;
	
	public CancelableDeleteAction(IWorkbenchPart part)
	{
		super(part);
		// TODO Auto-generated constructor stub
		setText("Delete");
		request = new Request(REQ_TYPE);
	}
	
	@Override
	public void run()
	{
		@SuppressWarnings("unchecked")
		List<AbstractElementNodeEditPart> parts = getSelectedObjects();
		
		CompoundCommand compoundCmd = new CompoundCommand();
		ElementDeleteCommand cmd;
		for(AbstractElementNodeEditPart p: parts)
		{
			cmd = (ElementDeleteCommand) p.getCommand(request);
			//cmd.setElement((NodeElement)p.getModel());
			compoundCmd.add(cmd);
		}
		
		execute(compoundCmd);
	}
	
	@Override
	public String getId()
	{
		return ID;
	}

}
